package LeetCode;

import java.util.ArrayList;
import java.util.List;

public class LeetCodeMain4 {
    List<List<String>> list=new ArrayList<>();
    List<String> list1=new ArrayList<>();
    StringBuilder st=new StringBuilder();
    public  List<List<String>> partition(String s) {
        backtracking1(s,0);
        return list;
    }
    public  void backtracking1(String s,int startIndex){
        if (startIndex>=s.length()){
            list.add(new ArrayList<>(list1));
            return;
        }
        for (int i = startIndex; i < s.length(); i++) {
            if (isPalindromicSubstring(s,startIndex,i)){
                String str1 = s.substring(startIndex,i+1);
                list1.add(str1);
            }else {
                continue;
            }
            backtracking1(s,i+1);
            list1.remove(list1.size()-1);
        }
    }
    public static boolean isPalindromicSubstring(String s,int start,int end){
        char[] ch=s.toCharArray();
        for (int i = start,j = end; i < j; i++, j--) {
            if (ch[i] != ch[j]) {
                return false;
            }
        }
        return true;
    }

//    public static void main2(String[] args) {
//        backtracking1("aab",0);
//        for (List<String> strings:list) {
//            System.out.println(strings.toString());
//        }
//    }
    public static void main1(String[] args) {
        int a=10;
        System.out.println(a);
        a=20;
        System.out.println(a);
        String s=new String("收到的");
        System.out.println(s.length());
    }
}
